package com.greyu.ysj.service.impl;


import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.greyu.ysj.entity.CbtRatio;
import com.greyu.ysj.entity.CbtRatioExample;
import com.greyu.ysj.mapper.CbtRatioMapper;
import com.greyu.ysj.service.CbtRatioService;

@Service
@Transactional
public class CbtRatioServiceImpl implements CbtRatioService {
	@Autowired
	private CbtRatioMapper cbtRatioMapper;



	@Override
	public CbtRatio selectRatioById(Integer Id) {
		CbtRatio cbtRatio=this.cbtRatioMapper.selectByPrimaryKey(Id);
		return cbtRatio;
	}

	@Override
	public float getRatio(Integer coinId, Integer investDuration) {
		CbtRatioExample CbtRatioExample = new CbtRatioExample();
		CbtRatioExample.Criteria criteria = CbtRatioExample.createCriteria();

        if (null != coinId) {
        	criteria.andCoinIdEqualTo(coinId);
        }
        if (null != investDuration) {
        	criteria.andInvestDurationEqualTo(investDuration);
        }
        List<CbtRatio> cbtRatioList = this.cbtRatioMapper.selectByExample(CbtRatioExample);

        CbtRatio cbtRatio;
        float ratio;
        try {
        	cbtRatio = cbtRatioList.get(0);
        	ratio=cbtRatio.getRatio();
        } catch (Exception e) {
            return 0;
        }
		return ratio;
	}

	@Override
	public List<CbtRatio> selectBycoinId(Integer coinId) {
		CbtRatioExample CbtRatioExample = new CbtRatioExample();
		CbtRatioExample.Criteria criteria = CbtRatioExample.createCriteria();

        if (null != coinId) {
        	criteria.andCoinIdEqualTo(coinId);
        }
        List<CbtRatio> cbtRatioList = this.cbtRatioMapper.selectByExample(CbtRatioExample);
        for(CbtRatio cbtRatio:cbtRatioList) {
        	System.out.println("cbtRatio"+cbtRatio);
        }
		return cbtRatioList;
	}



}
